import * as bm from "/js/baseModule.js";

export class Module extends bm.baseModule {
    constructor(view) {
        super(view);
        let that = this;

        //套餐详情渲染
        var mypack = globalData.pack;
        var userinfo = globalData.user;
        var province = globalData.province;

        that._serviceType = new Vue({
            el: '.ServiceType_vue',
            data: {
                types: that._typeList
            },
            methods: {
                clickType: function (type) {
                    //如果已经勾选
                    if (type.hasChoosed) {
                        type.hasChoosed = false;
                        //如果没有勾选
                    } else {
                        type.hasChoosed = true;
                    }
                },
                updateType: function () {
                    var array = {};
                    let types = that._typeList;
                    var num = 0;
                    for (let i = 0; i < types.length; i++) {
                        if (types[i].hasChoosed == true) {
                            array[types[i].id] = "YES";
                        } else {
                            array[types[i].id] = "";
                            num++;
                        }
                    }
                    if (num >= types.length) {
                        funs.tip("请至少选择一个业务类型", "", "fail");
                        return;
                    }
                    api.UpdateServiceType(array, {
                        succ: function (json) {
                            $.extend(true,globalData.user_tags,json.user_tags);
                            // funs.tip("修改业务类型成功", "", "succ", 1050);
                            globalData.user.has_set_business = true;
                            setTimeout(function () {
                                that._evt_goback();
                            }, 1200);
                        }, fail: function (error) {
                            if (error.status == '401') {
                                //未登录已经统一处理
                            } else if (error.status == '41009002') {
                                // funs.tip(error.msg, "请先去设置服务资料，成为工程商", "fail");
                            } else {
                                // funs.tip(error.msg, "", "fail");
                            }
                        }
                    });
                }
            }
        })

    }

    afterInstall() {
        //加载模块时
        this._serviceType.types = this._typeList = [
            {"id": "install", "name": "安装", "hasChoosed": globalData.user_tags.install},
            {"id": "repair", "name": "维修", "hasChoosed": globalData.user_tags.repair},
            {"id": "rent", "name": "租赁", "hasChoosed": globalData.user_tags.rent},
            {"id": "purchase", "name": "采购", "hasChoosed": globalData.user_tags.purchase}
        ];
    }


}